package cn.xrj.springcloud.controller;

import cn.xrj.springcloud.pojo.Qcpage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.List;

@RestController
public class QcpageConsumerController {
    @Autowired
    private RestTemplate restTemplate;
    //以下注释常量为未使用ribbon负载均衡时配置的
//    private static final String PRIFIX="http://localhost:8001";

    //开启负载均衡后，主机名与端口号使用服务名代替
    private static final String PRIFIX="http://SPRINGCLOUD-PROVIDER-JOBINFO";

    @RequestMapping("/consumer/jobinfo/getById/{id}")
    public Qcpage getById(@PathVariable("id")Integer id){
        return restTemplate.getForObject(PRIFIX+"/qcpage/getById/"+id,Qcpage.class);
    }

    @RequestMapping("/consumer/jobinfo/getAll")
    public List<Qcpage> getAll(){
        return restTemplate.getForObject(PRIFIX+"/qcpage/getAll",List.class);
    }

    @RequestMapping("/consumer/jobinfo/deleteById/{id}")
    public void deleteById(@PathVariable("id")Integer id){
         restTemplate.delete(PRIFIX+"/qcpage/deleteById/{id}",id);
    }
}
